package com.bainc.web.client;

import com.bainc.web.shared.LoginInfo;
import com.bainc.web.shared.UserProfile;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/*
 * Defines how the profile of a user will look like.
 */
public class UserProfilePage {

	static class ProfileServiceAsyncCallback implements AsyncCallback<UserProfile> {
		@Override
		public void onFailure(Throwable caught) {
		}

		@Override
		public void onSuccess(UserProfile profile) {
			loadUserProfile(profile);
		}
	}
	
	private static void loadUserProfile(UserProfile profile) {
		RootPanel rootPanel = RootPanel.get("jspage");
		rootPanel.clear();

		Label label = new Label(profile.toString());
		VerticalPanel panel = new VerticalPanel();
		panel.add(label);
		rootPanel.add(panel);	
	}
	
	public static void load(LoginInfo info) {
		ProfileServiceAsync service = GWT.create(ProfileService.class);
		ProfileServiceAsyncCallback callback = new ProfileServiceAsyncCallback();
		service.fetch(info, callback);
	}
}
